home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / pc / ps40sdk / examples / export / history / historyuiwin.c < prev   
Encoding:
C/C++ Source or Header  |  1996-10-29  |  8.5 KB  |  319 lines

  1. /*
  2.     File: History.c
  3.  
  4.     Copyright 1991-6, Adobe Systems Incorporated.
  5.     All rights reserved.
  6.  
  7.     C source file for Windows specific code for History example.
  8. */
  9.  
  10. #include "History.h"
  11.  
  12. /****************************************************************************/
  13.  
  14. void CheckAndEnable (GPtr globals, const HWND hDlg, int16 *currentResources, Str255 hS);
  15. void UpdateHistories(GPtr globals, const HWND hDlg, short count, Str255 hS);
  16.  
  17. /*****************************************************************************/
  18.  
  19. void DoAbout (GPtr globals)
  20. {
  21.     ShowAbout((AboutRecordPtr)gStuff, hDllInstance, AboutID);
  22. }
  23.  
  24. /*****************************************************************************/
  25. // This routine checks our values and update them accordingly whenever a
  26. // button gets pressed, so this routine will update the resources and populate
  27. // the dialog.
  28.  
  29. void CheckAndEnable (GPtr globals, const HWND hDlg, int16 *currentResources, Str255 hS)
  30. {
  31.  
  32.     *currentResources = CountPIResources(histResource);
  33.  
  34.     if (gCurrentHistory < 1)
  35.         gCurrentHistory = 1;
  36.     
  37.     if (gCurrentHistory > *currentResources)
  38.         gCurrentHistory = *currentResources;
  39.     
  40.     if (*currentResources <= histTotal ||
  41.         gCurrentHistory+histTotal > *currentResources)
  42.     {
  43.         if (GetFocus() == GetDlgItem(hDlg, downButton))
  44.             SetDialogDefaultItem(hDlg, ok); // set focus to OK since we're disabling
  45.         DisableControl (hDlg, downButton); // nothing extra to show
  46.     }
  47.     else
  48.         EnableControl (hDlg, downButton);
  49.  
  50.     
  51.     if (gCurrentHistory < 2)
  52.     {
  53.         if (GetFocus() == GetDlgItem(hDlg, upButton))
  54.             SetDialogDefaultItem(hDlg, ok); // set focus to OK since we're disabling
  55.         DisableControl (hDlg, upButton);
  56.     }
  57.     else
  58.         EnableControl (hDlg, upButton);
  59.  
  60.     if (*currentResources >= gCurrentHistory && *currentResources > 0)
  61.     { // enable trim buttons
  62.         EnableControl (hDlg, trimFirst);
  63.         EnableControl (hDlg, trimLast);
  64.     }
  65.     else
  66.     { // disable trim buttons
  67.         if (GetFocus() == GetDlgItem(hDlg, trimFirst) ||
  68.             GetFocus() == GetDlgItem(hDlg, trimLast))
  69.             SetDialogDefaultItem(hDlg, ok); // set focus to OK since we're disabling
  70.         DisableControl (hDlg, trimFirst);
  71.         DisableControl (hDlg, trimLast);
  72.     }
  73.  
  74.     UpdateHistories(globals, hDlg, *currentResources, hS);
  75. }
  76.  
  77. /*****************************************************************************/
  78.  
  79. BOOL WINAPI ExportProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)       // Win32 Change
  80. {
  81.     int                item, cmd;
  82.     short            numberErr = 0;
  83.     int32            x = 0;
  84.     static Str255    hS = ""; //histstatus
  85.     static int16    currentResources = 0; // static so retains value on calls
  86.     static int        lastItem = 0;
  87.     static GPtr        globals = NULL;          /* need to be static */
  88.  
  89.     switch  (wMsg)
  90.     {
  91.  
  92.         case  WM_INITDIALOG:
  93.  
  94.             /* set up globals    */
  95.  
  96.             globals = (GPtr) lParam;
  97.  
  98.             CenterDialog(hDlg);
  99.             
  100.             PIGetString(hS, kHistStatus); // get status string
  101.  
  102.             CheckAndEnable (globals, hDlg, ¤tResources, hS);
  103.             /* drop into PAINT */
  104.         case WM_PAINT:
  105.             // return FALSE;
  106.             break;
  107.  
  108.         case  WM_COMMAND:
  109.               item = COMMANDID (wParam);              // WIN32 Change
  110.             cmd = HIWORD (wParam);
  111.  
  112.             switch  (item)
  113.             {
  114.                 case trimFirst:
  115.                     if (cmd == BN_CLICKED)
  116.                     {
  117.                         if (currentResources >= gCurrentHistory)
  118.                         {
  119.                             DeletePIResource (histResource, gCurrentHistory);
  120.                             gStuff->dirty = TRUE;
  121.                         }
  122.                         CheckAndEnable (globals, hDlg, ¤tResources, hS);
  123.                         // checks buttons and values
  124.                         break;
  125.                     }
  126.                 case trimLast:
  127.                     if (cmd == BN_CLICKED)
  128.                     {
  129.                         if (currentResources >= gCurrentHistory + histTotal-1)
  130.                         {
  131.                             DeletePIResource (histResource,
  132.                                 (short)(gCurrentHistory + histTotal-1));
  133.                             gStuff->dirty = TRUE;
  134.                         }
  135.                         else if (currentResources > 0)
  136.                         {
  137.                             DeletePIResource (histResource,
  138.                                 (short)(currentResources));
  139.                             gStuff->dirty = TRUE;
  140.                         }
  141.                         CheckAndEnable (globals, hDlg, ¤tResources, hS);
  142.                         // checks buttons and values
  143.                         break;
  144.                     }
  145.                 case upButton:
  146.                     if (cmd == BN_CLICKED)
  147.                     {
  148.                         gCurrentHistory--;
  149.                         CheckAndEnable (globals, hDlg, ¤tResources, hS);
  150.                         break;
  151.                     }
  152.                 case downButton:
  153.                     if (cmd == BN_CLICKED)
  154.                     {
  155.                         gCurrentHistory++;
  156.                         CheckAndEnable (globals, hDlg, ¤tResources, hS);
  157.                         break;
  158.                     }
  159.                 case ok:
  160.                     if (cmd == BN_CLICKED)
  161.                     {
  162.                         EndDialog(hDlg, item); 
  163.                         return TRUE;
  164.                     }
  165.                     break;
  166.                 case cancel:
  167.                     if (cmd == BN_CLICKED)
  168.                     {
  169.                         gResult = userCanceledErr;
  170.                         EndDialog(hDlg, item);          // WIN32 change
  171.                         return TRUE;
  172.                     }
  173.                     // don't ever validate during cancel
  174.                     break;
  175.                 default:
  176.                     return FALSE;
  177.                     break;
  178.             } // switch (item)
  179.             break; // case WM_COMMAND
  180.         } // switch
  181.  
  182.     return  FALSE;
  183. }
  184.  
  185. /*****************************************************************************/
  186. short DoParameters (GPtr globals)
  187. {
  188.  
  189.     int    nResult;
  190.     PlatformData *platform;
  191.  
  192.     platform = ((ExportRecordPtr) gStuff)->platformData;
  193.  
  194.     /* Query the user for percent dissolve. */
  195.  
  196.     nResult = DialogBoxParam(hDllInstance,
  197.                              (LPSTR)"HISTORYPARAM",
  198.                              (HWND)platform->hwnd,
  199.                              (FARPROC)ExportProc,
  200.                              (LPARAM)globals);
  201.  
  202.     return (nResult == ok);
  203.  
  204. }    
  205.  
  206. /****************************************************************************/
  207. /* Populate dialog with history strings. */
  208.  
  209. void UpdateHistories (GPtr globals, const HWND hDlg, short count, Str255 hS)
  210. {
  211.     Str255 s = "";
  212.         
  213.     Str255 n1 = ""; // for "^0 to ^1 of ^2"
  214.     Str255 n2 = ""; //
  215.     Str255 nT = ""; //
  216.     Str255 ss = ""; //
  217.  
  218.     long    x = gCurrentHistory + (histTotal - 1);
  219.     short    loop;
  220.  
  221.     PICopy(ss, hS, hS[0]+1); // make a new copy
  222.  
  223.     for (loop = gCurrentHistory; loop < gCurrentHistory + histTotal; loop++)
  224.     {
  225.         GetHistory (globals, loop, s);
  226.         if (loop == gCurrentHistory && !s[0])
  227.         {
  228.             PIGetString(s, kNoHistories);
  229.             ss[ (ss[0] = 0)+1 ] = 0; // none
  230.         }
  231.         StuffText (hDlg, (short)(histItem1 + (loop - gCurrentHistory)), s);
  232.         if (s[0] < 1 && x > loop-1)
  233.             x = loop-1;
  234.     }
  235.  
  236.     if (ss[0] > 0)
  237.     { // got the display string.  Populate it.
  238.         NumToString(gCurrentHistory, n1);
  239.         NumToString(x, n2);
  240.         NumToString(count, nT);
  241.         PIParamText(ss, n1, n2, nT);
  242.     }
  243.     StuffText (hDlg, statusText, ss);
  244.     // even if nothing, stuff empty or string in field
  245. }
  246.  
  247. /****************************************************************************/
  248. /* Example for ShowAlert() function which takes a string ID as parameter    */
  249. /* and displays a message box                                               */
  250. /****************************************************************************/
  251.  
  252. short ShowAlert (short stringID)
  253. {
  254.     char szMessage[256];
  255.     char szTitle[128];
  256.  
  257.     LoadString(hDllInstance, stringID, szMessage, sizeof szMessage);
  258.     LoadString(hDllInstance, 2, szTitle, sizeof szTitle);
  259.     return  ( MessageBox((HWND)NULL, (LPSTR)szMessage, (LPSTR)szTitle, MB_OK | MB_ICONHAND) );
  260.  
  261. }
  262.  
  263. /*****************************************************************************/
  264.  
  265. /* Initialization and termination code for window's dlls. */
  266.  
  267. /* ------------------------------------------------
  268.  *   Code from Borland's window's dll example code.
  269.  * ------------------------------------------------
  270.  */
  271. #if defined(__BORLANDC__)
  272. // Turn off warning: Parameter '' is never used; effects next function only
  273. #pragma argsused
  274. #endif
  275.  
  276. #ifdef WIN32
  277.  
  278. // Every 32-Bit DLL has an entry point DLLInit
  279.  
  280. BOOL APIENTRY DLLInit(HANDLE hInstance, DWORD fdwReason, LPVOID lpReserved)
  281. {
  282.  
  283.     if (fdwReason == DLL_PROCESS_ATTACH)
  284.         hDllInstance = hInstance;
  285.  
  286.     return TRUE;   // Indicate that the DLL was initialized successfully.
  287. }
  288.  
  289. #else
  290. // Every 16-Bit DLL has an entry point LibMain and an exit point WEP.
  291. int FAR PASCAL LibMain( HANDLE hInstance, WORD wDataSegment,
  292.                                    WORD wHeapSize, LPSTR lpszCmdLine )
  293. {
  294.     // Required when using Zortech; causes blink to include startup code
  295.     extern __acrtused_dll;
  296.  
  297.     // The startup code for the DLL initializes the local heap (if there is one)
  298.     // with a call to LocalInit which locks the data segment.
  299.     if ( wHeapSize != 0 )
  300.         UnlockData( 0 );
  301.  
  302.     hDllInstance = hInstance;
  303.     return 1;   // Indicate that the DLL was initialized successfully.
  304. }
  305.  
  306. int FAR PASCAL WEP(int nParam)
  307. {
  308.     switch  (nParam) {
  309.       case  WEP_SYSTEM_EXIT: // System shutdown in progress
  310.       case  WEP_FREE_DLL   : // DLL use count is 0
  311.       default :              // Undefined;  ignore
  312.             return  1;
  313.     }
  314. }
  315. #endif
  316. /*****************************************************************************/
  317.  
  318.  
  319.